﻿using JStore.Core.Entities;
using SpeadFrm.MvcPager;
using SpeadFrm.ORM;

namespace JStore.Data.Daos
{
    public class NewsDao : BaseDao<News>
    {
        public News GetById(int id)
        {
            var sql = Sql.Builder.Where("Id = @0", id);
            return FirstOrDefault(sql);
        }

        public PagedList<News> GetPagedList(int pageIndex, int pageSize)
        {
            var sql = Sql.Builder.Where("1=1").OrderBy("CreateDate DESC");
            return PagedList(pageIndex, pageSize, sql);
        }

        public void DeleteById(int id)
        {
            var sql = Sql.Builder.Where("Id = @0", id);
            Delete(sql);
        }
    }
}